package controller;

import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;
import model.College;
import model.Group;

@SuppressWarnings("serial")
public class TableModelGroup extends AbstractTableModel {

	private ArrayList<Group> list;
	
	public TableModelGroup(){
		list = new ArrayList<Group>(College.getInstance().getAllGroups());
	}
	// Set number of columns
	public int getColumnCount() {

		return 1;
	}
	
	// Set number of rows
	public int getRowCount() {
		
		int count = College.getInstance().getAllGroups().size();
		return count;
	}

	// Fill the rows with all the groups
	public Object getValueAt(int row, int col) {
		list = new ArrayList<Group>(College.getInstance()
				.getAllGroups());
		switch (col) {
		case 0:
			return list.get(row).getGroup_name();
		}
		return null;
	}

	// Set column names
	public String getColumnName(int column) {
		switch (column) {
		case 0:
			return "Klas";
		}
		return null;
	}
	
	public Group getSelectedRowObject(int rowIndex){
		return list.get(rowIndex);
	}
}
